package com.example.androidaudiovideodemo.activity

import android.graphics.Color
import android.util.Log
import android.view.ViewTreeObserver
import android.widget.FrameLayout
import com.example.androidaudiovideodemo.*
import com.example.androidaudiovideodemo.base.BaseActivity
import kotlinx.android.synthetic.main.activity_opengl_draw_image.*
import kotlinx.android.synthetic.main.activity_opengl_draw_image.line
import kotlinx.android.synthetic.main.activity_opengl_draw_triangle.*

/**
 *
 * author: renbing
 *
 * date: 2022/1/25
 *
 * des:6. 学习 Android 平台 OpenGL ES API，学习纹理绘制，能够使用 OpenGL 显示一张图片
 */
class OpenGLDrawImageActivity : BaseActivity(){


    override fun getLayoutId() = R.layout.activity_opengl_draw_image

    override fun performInit() {
        super.performInit()

        setStatusBarColor(this,true)
    }

    override fun initData() {
        super.initData()
        //返回按钮
        task_six_title_view.run {
            setLeftIconColorFilter(Color.BLACK)
            setOnLeftIconClickListener {
                finish()
            }
        }

        line.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener{
            override fun onGlobalLayout() {
                line.viewTreeObserver.removeOnGlobalLayoutListener(this)
                Log.e("TAG","${line.top}")

                val layoutParams = FrameLayout.LayoutParams(
                    FrameLayout.LayoutParams.MATCH_PARENT,
                    FrameLayout.LayoutParams.MATCH_PARENT)
                layoutParams.setMargins(0,line.top+2,0,0)
                addContentView(ImageTextureGLSurfaceView(ImageTextureRenderer(this@OpenGLDrawImageActivity),this@OpenGLDrawImageActivity),layoutParams)
            }
        })
    }
}